from sentence_transformers import SentenceTransformer

# 加载开源模型
model = SentenceTransformer("BAAI/bge-large-zh")

# 输入财经文本
text1 = "苹果公司宣布股票回购计划"
text2 = "Apple 发布了新的股份回购公告"

# 转向量
vec1 = model.encode(text1)
vec2 = model.encode(text2)

# 计算相似度
from numpy import dot
from numpy.linalg import norm
similarity = dot(vec1, vec2) / (norm(vec1) * norm(vec2))
print("相似度：", similarity)
